--------------------------------------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  X:\shared\ambulance\Work\replicationpackage\logs\litigation_patlevel.log
  log type:  text
 opened on:  15 Jul 2024, 10:05:54

. 
. /*******************************************************************************
> litigation_patlevel
> 
> Conducts analysis of litigation at the patient panel
> *******************************************************************************/
. 
. clear all

. 
. qui {

. 
. foreach l in civ crim {
  2.         qui {
  3.                 bysort usrds_id post_`l': egen totalrides_pre_`l'=sum(NEdialysisrides) if post_`l'==0
  4.                 bysort usrds_id: egen pre_ride_tot_`l'=max(totalrides_pre_`l')
  5.                 gen freqride_`l'=(pre_ride_tot_`l'>=100 & !missing(pre_ride_tot_`l'))
  6.                 
.                 gen postwindow_`l'=0 if t>=`l'_date-24 & t<`l'_date
  7.                 replace postwindow_`l'=1 if  t<`l'_date+24 & t>=`l'_date
  8.                 bysort usrds_id dist_code postwindow_`l': egen totalrides_prewindow_`l'=sum(NEdialysisrides) if postwindow_`l'==0
  9.                 bysort usrds_id dist_code postwindow_`l': egen totalrides_postwindow_`l'=sum(NEdialysisrides) if postwindow_`l'==1
 10.                 bysort usrds_id dist_code: egen pre_totalrides_`l'=max(totalrides_prewindow_`l') if !missing(postwindow_`l')
 11.                 bysort usrds_id dist_code: egen post_totalrides_`l'=max(totalrides_postwindow_`l') if !missing(postwindow_`l')
 12.                 bysort usrds_id dist_code postwindow_`l': egen totalridemo_prewindow_`l'=sum(any_ride) if postwindow_`l'==0
 13.                 bysort usrds_id dist_code postwindow_`l': egen totalridemo_postwindow_`l'=sum(any_ride) if postwindow_`l'==1
 14.                 bysort usrds_id dist_code: egen pre_totalridemo_`l'=max(totalridemo_prewindow_`l') if !missing(postwindow_`l')
 15.                 bysort usrds_id dist_code: egen post_totalridemo_`l'=max(totalridemo_postwindow_`l') if !missing(postwindow_`l')
 16.                 
.         }
 17.         
.         *Figures A14 and A15, Panel (a)
.         twoway (hist pre_totalrides_`l' if pre_totalridemo_`l'>0, ///
>                         width(20) start(-0.00001)) ///
>                 (hist post_totalrides_`l' if post_totalridemo_`l'>0, ///
>                         width(20) start(-0.00001) fcolor(none) lcolor(black)) if pat_flag==1, ///
>                 xti("") yti(Empirical Probability Density) ///
>                 graphregion(color(white)) bgcolor(white) ///
>                 leg(subti("Total Rides in the...") order(1 "Pre-Period" 2 "Post-Period"))
 18.         if "`l'"=="civ" {
 19.                 qui graph export "${outpath}Figure_A14a.pdf", as(pdf) replace
 20.         }
 21.         if "`l'"=="crim" {
 22.                 qui graph export "${outpath}Figure_A15a.pdf", as(pdf) replace
 23.         }
 24.         
.         *Figures A14 and A15, Panel (b)
.         twoway (hist pre_totalridemo_`l' if pre_totalridemo_`l'>0, ///
>                         width(0.99999) start(0.99999)) ///
>                 (hist post_totalridemo_`l' if post_totalridemo_`l'>0, ///
>                         width(0.99999) start(0.99999) fcolor(none) lcolor(black)) if pat_flag==1, ///
>                 xti("") yti(Empirical Probability Mass) ///
>                 graphregion(color(white)) bgcolor(white) ///
>                 leg(subti("Total Months Riding in the...") order(1 "Pre-Period" 2 "Post-Period"))
 25.         if "`l'"=="civ" {
 26.                 qui graph export "${outpath}Figure_A14b.pdf", as(pdf) replace
 27.         }
 28.         if "`l'"=="crim" {
 29.                 qui graph export "${outpath}Figure_A15b.pdf", as(pdf) replace
 30.         }
 31.         
. }

. 
. qui {

.                            
. *Effect of litigation
. foreach l in civ crim {
  2.         qui {
  3.                 gen months_since_`l'=t-`l'_date if `l'_date>=528 & `l'_date<=684
  4.                 su months_since_civ
  5.                 replace months_since_`l'=. if months_since_`l'<-12 | months_since_`l'>=12
  6.                 su months_since_civ
  7.                 replace months_since_`l'=-50 if missing(`l'_date)
  8.                 su months_since_civ
  9.                 replace months_since_`l'=months_since_`l'+100
 10.                 su months_since_civ
 11.                 gen post_together_`l'=months_since_`l'
 12.                 replace post_together_`l'=100 if months_since_`l'>=100 & !missing(months_since_`l')
 13.                 
.                 if "`l'"=="civ" {
 14.                         local other_treat = "i.post_crim"
 15.                         label define PA 100 "Civil Enforcement", replace
 16.                         local xti = "Months Since Civil Enforcement"
 17.                 }
 18.                 if "`l'"=="crim" {
 19.                         local other_treat = "i.post_civ"
 20.                         label define PA 100 "Criminal Enforcement", replace
 21.                         local xti = "Months Since Criminal Enforcement"
 22.                 }
 23.                 
.                 *Getting estimates for Tables A26-31
>                 local i = 1
>                 foreach var in dialsess death hosp_any hosp_fluid1 rider_death rider_hosp rider_ridesnext {
> 
>                         estimates clear
>                         eststo est1: reghdfe `var' ib99.post_together_`l' $pat_controls $fac_controls i.prior_auth `other_treat', a(t newprovusrd dist
> _code) vce(cluster dist_code)
>                         eststo est1,addscalars(time_FE 1)
>                         eststo est1,addscalars(dist_FE 1)
>                         eststo est1,addscalars(Cont 1)
>                         eststo est1,addscalars(Fac_FE 1)
>                         eststo est1,addscalars(Pat_FE 0)
>                         estadd ysumm
>                         estimates save ${estpath}litigation_`var'_posttogether_`l',replace
> 
>                         if `i'<=4 {
>                                 estimates clear
>                                 eststo est1: reghdfe `var' ib99.post_together_`l' $pat_controls $fac_controls i.prior_auth `other_treat' if freqride_`
> l'==1, a(t dist_code newprovusrd) vce(cluster dist_code)
>                                 eststo est1,addscalars(time_FE 1)
>                                 eststo est1,addscalars(dist_FE 1)
>                                 eststo est1,addscalars(Cont 1)
>                                 eststo est1,addscalars(Fac_FE 1)
>                                 eststo est1,addscalars(Pat_FE 0)
>                                 estadd ysumm
>                                 estimates save ${estpath}litigation_`var'_posttogether_freqride_`l',replace
>                         }
>                         
>                         local i = `i'+1
>                 }
.                         
.                 *Tables A26 and A27
.                 estimates clear
 24.                 local i = 1
 25.                 foreach var in dialsess death hosp_any hosp_fluid1 {
 26.                         estimates use ${estpath}litigation_`var'_posttogether_`l'
 27.                         estimates store est`i'
 28.                         local i = `i'+1
 29.                 }
 30. 
.                 label var dialsess "Dialysis Sessions"
 31.                 label var death "Mortality"
 32.                 label var hosp_any "All-Cause Hosp."
 33.                 label var hosp_fluid1 "Fluid Hosp."
 34.                 label values post_together_`l' PA
 35.                 
.                 if "`l'"=="civ" {
 36.                         local name "A26"
 37.                 }
 38.                 if "`l'"=="crim" {
 39.                         local name "A27"
 40.                 }
 41.                 
.                 esttab est* using ${outpath}Table_`name'.tex, ///
>                         star(+ 0.1 * 0.05 ** 0.01 *** 0.001) ///
>                         replace keep(100.post_together_`l') label se stats(time_FE dist_FE Cont Fac_FE r2 ymean N, ///
>                         label("Year-Month FE" "District FE" "Pat/Fac Controls" "Facility FE" ///
>                         "R-squared" "Dep. Var. Mean" "Observations")) frag      booktabs
 42.                 
.                 *Tables A28 and A29
.                 estimates clear
 43.                 local i = 1
 44.                 foreach var in dialsess death hosp_any hosp_fluid1 {
 45.                         estimates use ${estpath}litigation_`var'_posttogether_freqride_`l'
 46.                         estimates store est`i'
 47.                         local i = `i'+1
 48.                 }
 49.                 
.                 if "`l'"=="civ" {
 50.                         local name "A28"
 51.                 }
 52.                 if "`l'"=="crim" {
 53.                         local name "A29"
 54.                 }
 55.                 
.                 esttab est* using ${outpath}Table_`name'.tex, ///
>                         star(+ 0.1 * 0.05 ** 0.01 *** 0.001) ///
>                         replace keep(100.post_together_`l') label se stats(time_FE dist_FE Cont Fac_FE r2 ymean N, ///
>                         label("Year-Month FE" "District FE" "Pat/Fac Controls" "Facility FE" ///
>                         "R-squared" "Dep. Var. Mean" "Observations")) frag      booktabs
 56. 
.                 *Tables A30 and A31
.                 estimates clear
 57.                 local i = 1
 58.                 foreach var in rider_ridesnext rider_hosp rider_death {
 59.                         estimates use ${estpath}litigation_`var'_posttogether_`l'
 60.                         estimates store est`i'
 61.                         local i = `i'+1
 62.                 }
 63. 
.                 label var rider_ridesnext "Rides Next Month"
 64.                 label var rider_hosp "Hospitalizations"
 65.                 label var rider_death "Mortality"
 66.                 
.                 if "`l'"=="civ" {
 67.                         local name "A30"
 68.                 }
 69.                 if "`l'"=="crim" {
 70.                         local name "A31"
 71.                 }
 72.                 
.                 esttab est* using ${outpath}Table_`name'.tex, ///
>                         star(+ 0.1 * 0.05 ** 0.01 *** 0.001) ///
>                         replace keep(100.post_together_`l') label se stats(time_FE dist_FE Cont Fac_FE r2 ymean N, ///
>                         label("Year-Month FE" "District FE" "Pat/Fac Controls" "Facility FE" ///
>                         "R-squared" "Dep. Var. Mean" "Observations")) frag      booktabs        
 73. 
.         }
 74.         
.         label var rider_ridesnext "Rides Next Month"
 75.         label var rider_death "Mortality Rate Among Riders"
 76.         label var rider_hosp "Hospitalization Rate Among Riders"
 77. 
.         *Figures A16 and A17
.         foreach var in rider_death rider_hosp rider_ridesnext {
 78.                 local varlabel : variable label `var'
 79.                 estimates clear
 80.                 qui eststo: reghdfe `var' ib99.months_since_`l' $pat_controls $fac_controls i.prior_auth `other_treat', a(t newprovusrd dist_code)
>  vce(cluster dist_code)
.                 qui estimates save ${estpath}litigation_`var'_noparboth_wFE_`l',replace
 81.                 coefplot, recast(connected) ciopts(recast(rcap)) baselevel ///
>                         keep(*months_since_`l') drop(50*) vert ///
>                         xline(13, lcolor(gs8) lpattern(dash)) ///
>                         xti("`xti'") ///
>                         xlab(1 "-12" 4 "-9" 7 "-6" 10 "-3" 13 "0" 16 "3" 19 "6" 22 "9" 25 "12") ///
>                         yline(0, lcolor(gs8)) ///
>                         yti("`varlabel'") ylab(, angle(0)) ///
>                         graphregion(color(white)) bgcolor(white)
 82.                 if "`var'"=="rider_ridesnext" & "`l'"=="civ" {
 83.                         qui graph export "${outpath}Figure_A16a.pdf", as(pdf) replace
 84.                 }
 85.                 if "`var'"=="rider_ridesnext" & "`l'"=="crim" {
 86.                         qui graph export "${outpath}Figure_A17a.pdf", as(pdf) replace
 87.                 }
 88.                 if "`var'"=="rider_hosp" & "`l'"=="civ" {
 89.                         qui graph export "${outpath}Figure_A16b.pdf", as(pdf) replace
 90.                 }
 91.                 if "`var'"=="rider_hosp" & "`l'"=="crim" {
 92.                         qui graph export "${outpath}Figure_A17b.pdf", as(pdf) replace
 93.                 }
 94.                 if "`var'"=="rider_death" & "`l'"=="civ" {
 95.                         qui graph export "${outpath}Figure_A16c.pdf", as(pdf) replace
 96.                 }
 97.                 if "`var'"=="rider_death" & "`l'"=="crim" {
 98.                         qui graph export "${outpath}Figure_A17c.pdf", as(pdf) replace
 99.                 }
100.         }
101. }

. 
. log close
      name:  <unnamed>
       log:  X:\shared\ambulance\Work\replicationpackage\logs\litigation_patlevel.log
  log type:  text
 closed on:  15 Jul 2024, 10:59:26
--------------------------------------------------------------------------------------------------------------------------------------------------------
